// pages/home/home.js
import api from '../../utils/api.js';
import cache from '../../utils/cache.js';
import http from '../../utils/http.js';
import tools from '../../utils/tools.js';
const Http = new http;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: 'home',
    list: [{
        value: 'home',
        icon: 'home',
        ariaLabel: '首页'
      },
      {
        value: 'app',
        icon: 'app',
        ariaLabel: '软件'
      },
      {
        value: 'chat',
        icon: 'chat',
        ariaLabel: '聊天'
      },
      {
        value: 'my',
        icon: 'user',
        ariaLabel: '我的'
      },
    ],
    stickyProps: {
      zIndex: 1,
      zList: []
    },
    typeList: [{
      title: '全部'
    }]
  },
  handleBack() {
    wx.navigateBack();
  },
  handleFocus() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },
  onTabsChange(e) {
    let sid = e.detail.value;
    this.getTypeList(sid);
  },
  onChange: tools.debounce(function (e) {
    console.log(e);
  }),
  onCellClick: function (e) {
    console.log(e.target.id);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    // 获取科目
    this.getSubjectList();
  },
  getSubjectList: function () {
    let _that = this;
    Http.httpReq({
      url: api.getSubjectList,
    }).then(ret => {
      let data = ret.data.data;
      this.setData({
        stickyProps: {
          zIndex: _that.data.stickyProps.zIndex,
          zList: data
        }
      })

      // 获取课程
      this.getTypeList(this.data.stickyProps.zIndex);
    })
  },
  getTypeList: function (sid) {
    Http.httpReq({
      url: api.getTypeList,
      data: {
        sid: sid
      }
    }).then(ret => {
      let data = ret.data.data;
      this.setData({
        typeList: data
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (e.zIndex != null) {
      this.setData({
        stickyProps: {
          zIndex: e.zIndex,
        }
      })
    }
    this.getSubjectList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})